<template>
  <div class="components-container">
    <!-- 绑定 -->
    <sweet-modal ref="dialog" class="dialog">
      <h3>{{title}}</h3>
      <div class="layui-form-item">
        <label class="layui-form-label">业务编号</label>
        <div class="layui-input-inline">
          <el-input v-model="reg.REGBUSNUM" style="width:500px;"></el-input>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">火化序号</label>
        <div class="layui-input-inline">
          <el-input v-model="reg.REGDAYNUM" style="width:500px;" @keyup.enter.native="submit"></el-input>
        </div>
      </div>
      <div class="layui-form-item btnCenter sweet-btn">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="submit">确定</el-button>
      </div>
    </sweet-modal>
    <!-- 详情 -->
    <sweet-modal ref="info" class="dialog" :sweetModalMaxWidth="pageWidth">
      <h3>{{title}}</h3>
      <div :style="{maxHeight:maxHeight+'px'}" style="overflow:auto;">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 0px;">
          <legend>死者信息</legend>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">逝者类型</label>
              <div class="layui-input-inline">
                <el-input v-model="regData.REGBONETYPE" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">到馆时间</label>
              <div class="layui-input-inline">
                <el-date-picker type="datetime" v-model="regDateTimeInfo" format="yyyy-MM-dd HH:mm" readonly></el-date-picker>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">证件类型</label>
              <div class="layui-input-inline">
                <el-input v-model="regData.REGCARDTYPE" readonly></el-input>
              </div>
            </div>

            <div class="layui-inline">
              <label class="layui-form-label">逝者姓名</label>
              <div class="layui-input-inline">
                <el-input v-model="regData.REGNAME" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">逝者性别</label>
              <div class="layui-input-inline">
                <el-input v-model="regData.REGSEXDESC" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">证件号码</label>
              <div class="layui-input-inline">
                <el-input v-model="regData.REGCARDNO" readonly></el-input>
              </div>
            </div>

            <div class="layui-inline">
              <label class="layui-form-label">详细地址</label>
              <div class="layui-input-inline">
                <el-input class="longertext" readonly v-model="regData.REGDETAILADDRESS">
                </el-input>
              </div>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">出生日期</label>
              <div class="layui-input-inline">
                <el-date-picker type="date" readonly v-model="regDataEexend.RegBirthDate"></el-date-picker>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">死亡日期</label>
              <div class="layui-input-inline">
                <el-date-picker type="date" readonly v-model="regDataEexend.regDeathDate"></el-date-picker>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">逝者年龄</label>
              <div class="layui-input-inline">
                <el-input readonly v-model="regData.REGAGE"></el-input>
              </div>
            </div>

            <div class="layui-inline">
              <label class="layui-form-label">死亡原因</label>
              <div class="layui-input-inline">
                <el-input v-model="regData.REGCAUSADESC" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">火化日期</label>
              <div class="layui-input-inline">
                <el-date-picker type="date" readonly v-model="regDataEexend.regCremationDate"></el-date-picker>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">排队序号</label>
              <div class="layui-input-inline">
                <el-input v-model="regData.REGDAYNUM" readonly></el-input>
              </div>
            </div>

            <div class="layui-inline">
              <label class="layui-form-label">民族</label>
              <div class="layui-input-inline">
                <el-input v-model="regData.REGNATION" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">户籍类别</label>
              <div class="layui-input-inline">
                <el-input v-model="regData.REGHOUSEHOLDTYPE" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">户籍地址</label>
              <div class="layui-input-inline">
                <el-input v-model="regData.REGHOUSEHOLDDESC" readonly></el-input>
              </div>
            </div>

            <div class="layui-inline">
              <label class="layui-form-label">统计地址</label>
              <div class="layui-input-inline">
                <el-input v-model="addressInfo" readonly></el-input>
              </div>
            </div>
          </div>
        </fieldset>
        <fieldset class="layui-elem-field layui-field-title">
          <legend>家属信息</legend>
          <div class="layui-field-box">
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">家属姓名</label>
                <div class="layui-input-inline">
                  <el-input v-model="regData.REGHANDLERNAME" readonly></el-input>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">家属性别</label>
                <div class="layui-input-inline">
                  <el-input v-model="regData.REGHANDSEXDESC" readonly></el-input>
                </div>
              </div>

              <div class="layui-inline">
                <label class="layui-form-label">详细地址</label>
                <div class="layui-input-inline">
                  <el-input class="longertext" :autosize="{ minRows: 2, maxRows: 4}" readonly v-model="regData.REGHANDLERHOUSEHOLD">
                  </el-input>
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">证件号码</label>
                <div class="layui-input-inline">
                  <el-input v-model="regData.REGHANDLERCARDNO" readonly></el-input>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-inline">
                  <el-input v-model="regData.REGHANDLERLINK" readonly></el-input>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">逝者关系</label>
                <div class="layui-input-inline">
                  <el-input v-model="regData.REGRELATION" readonly></el-input>
                </div>
              </div>
            </div>
          </div>
        </fieldset>
        <fieldset class="layui-elem-field layui-field-title">
          <legend>火化信息</legend>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">减免类型</label>
              <div class="layui-input-inline">
                <el-input v-model="regData.REGISKEYPOINTDESC" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">骨灰去向</label>
              <div class="layui-input-inline">
                <el-input v-model="regData.REGGHQXDESC" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">服务方式</label>
              <div class="layui-input-inline">
                <el-input v-model="regData.REGYITIQXDESC" readonly></el-input>
              </div>
            </div>

            <div class="layui-inline">
              <label class="layui-form-label">接尸车辆</label>
              <div class="layui-input-inline">
                <el-input v-model="cdhdata.CARLIC" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">驾驶员</label>
              <div class="layui-input-inline">
                <el-input v-model="cdhdata.STANAME" readonly></el-input>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">里程数</label>
              <div class="layui-input-inline">
                <el-input v-model="cdhdata.CDHMILEAGE" :min="0" style="width:150px" readonly></el-input>公里
              </div>
            </div>

            <div class="layui-inline">
              <label class="layui-form-label">接尸地点</label>
              <div class="layui-input-inline">
                <el-input class="longertext" v-model="regData.REGADDRESS" readonly></el-input>
              </div>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">备注</label>
              <div class="layui-input-inline">
                <el-input class="longertext" v-model="regData.REGREMARK" readonly></el-input>
              </div>
            </div>
          </div>
        </fieldset>
      </div>
      <div class="layui-form-item btnCenter sweet-btn">
        <el-button @click="infoClose">取消</el-button>
      </div>
    </sweet-modal>
  </div>
</template>

<style rel="stylesheet/scss" lang="scss" scoped>
  .el-button+.el-button {
    margin-left: 0;
  }

  .longtext {
    width: 480px;
  }

  .longertext {
    width: 480px;
  }

  .sweet-btn {
    margin-top: 20px;
  }

</style>
<script>
  import apiBase from "@/api/apiBase.js";
  import sweetModal from "@/components/sweetModal";
  import {
    formatDate,
    timeStringToDate,
    dateStringToDate
  } from "@/utils/date.js";
  import {
    manage
  } from "@/mixins/managePage.js";
  const Modify = "序号绑定";
  const Detail = "详情";
  export default {
    mixins: [manage],
    data() {
      return {
        pageWidth: 1250,
        maxHeight: 550,
        regDataEexend: {
          regDeathDate: null,
          regDataTime: null,
          RegBirthDate: null,
          regCremationDate: null
        },
        reg: {
          REGID: null,
          REGDAYNUM: null,
          REGBUSNUM: null
        },
        regDateTimeInfo: null,
        addressInfo: null,
        carryAreaInfo: null,
        cdhdata: {
          CARCODNAME: null,
          CDHCARID: null,
          CARLIC: null,
          CDHDRIVER: null,
          STANAME: null,
          CDHMILEAGE: null
        },
        cdhdataEexend: {
          cardata: []
        },
        regData: {
          REGID: null,
          REGPRPID: null,
          REGDATE: null,
          REGTIME: null,
          REGDAYNUM: null,
          REGBONETYPE: null,
          REGCAUSA: null,
          REGCAUSASON: null,
          REGDEATHID: null,
          REGREGPROVEUNIT: null,
          REGADDRESS: null,
          REGDEATHADDRESS: null,
          REGYITIQX: null,
          REGGHQX: null,
          REGNAME: null,
          REGSEX: null,
          REGAGE: null,
          REGCARDTYPE: null,
          REGCARDNO: null,
          REGBIRTHDATE: null,
          REGNATIONALITYTYPE: null,
          REGNATION: null,
          REGCULTURALDEGREE: null,
          REGMARRIAGE: null,
          REGJOB: null,
          REGPOLITICAL: null,
          REGHOUSEHOLDTYPE: null,
          REGHOUSETYPE: null,
          REGHOUSEHOLD: null,
          REGDETAILADDRESS: null,
          REGDEATHDATE: null,
          REGISKEYPOINT: null,
          REGHANDLERNAME: null,
          REGHANDSEX: null,
          REGHANDLERCARDTYPE: null,
          REGHANDLERCARDNO: null,
          REGHANDLERHOUSEHOLD: null,
          REGHANDLERLINK: null,
          REGRELATION: null,
          REGREMARK: null,
          //里程数
          REGLCS: null,
          //车辆信息
          REGCLXX: [],
          //驾驶员
          REGJSY: null
        },
      }
    },
    methods: {
      open(order, currentRow) {
        this.order = order;
        this.reg.REGBUSNUM = null;
        this.reg.REGDAYNUM = null;
        switch (this.order) {
          case Modify:
            this.title = "序号绑定";
            this.$refs.dialog.open();
            break;
          case Detail:
            this.title = "详情";
            this.dataInfo(currentRow.REGID);
            this.$refs.info.open();
            break;
          default:
        }
      },
      closeDialog() {
        this.$refs.dialog.close();
      },
      //提交
      submit() {

        switch (this.order) {
          case Modify:

            this.dataModify();
            break;
          default:
        }
      },
      dataModify() {
        console.log('reg', this.reg)
        let data = {
          REGDAYNUM: this.reg.REGDAYNUM,
          REGBUSNUM: this.reg.REGBUSNUM
        };
        console.log('data', data);
        apiBase.DoService(
          data,
          apiBase.getApiAdress().NumBinding.BindingNumByBussNo,
          res => {
            this.$refs.dialog.close();
            this.$message({
              type: "success",
              message: "绑定成功!"
            });
            this.refreshData();
          });
      },
      dataInfo(id) {
        this.reg.REGID = id;
        let Data = JSON.parse(JSON.stringify(this.reg));
        apiBase.DoService(
          Data,
          apiBase.getApiAdress().NumBinding.Detail,
          res => {
            this.regData = res.data.content;
            //console.log('regData',this.regData)
            this.regDateTimeInfo = timeStringToDate(
              this.regData.REGTIME,
              this.regData.REGDATE
            );
            this.regDataEexend.regDataTime = timeStringToDate(
              this.regData.REGTIME,
              this.regData.REGDATE
            );
            this.regDataEexend.regDeathDate = dateStringToDate(
              this.regData.REGDEATHDATE
            );
            this.regDataEexend.RegBirthDate = dateStringToDate(
              this.regData.REGBIRTHDATE
            );
            this.regDataEexend.regCremationDate = dateStringToDate(
              this.regData.REGCREMATIONDATE
            );
            let cdhdata = this.regData.Cdh;
            if (cdhdata) {
              this.cdhdataEexend.cardata = [cdhdata.CARCODNAME, cdhdata.CDHCARID];
              this.cdhdata.CARLIC = cdhdata.CARLIC;
              this.cdhdata.CDHDRIVER = cdhdata.CDHDRIVER;
              this.cdhdata.CDHMILEAGE = cdhdata.CDHMILEAGE;
              this.cdhdata.STANAME = cdhdata.STANAME;
            }
          });
      },
      refreshData() {
        this.$emit("refreshData");
      },

    },
    components: {
      sweetModal
    }
  };

</script>
